#include "MaintaintSetView.h"
#include "ui_MaintaintSetForm.h"

MaintaintSetView::MaintaintSetView(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MaintaintSetView)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    m_settingHelper = SettingHelper::getSettingHelper();
    readSetting();
}

MaintaintSetView::~MaintaintSetView()
{
    delete ui;
}

void MaintaintSetView::readSetting()
{
    m_settingHelper->maintainReadSetting();

    ui->nu_autodormantwaittime->setText(QString::number(m_settingHelper->m_MaintainSet.sleepTime));
    ui->maintaintimeEdit->setTime(QTime::fromString(m_settingHelper->m_MaintainSet.preMtTime,"hh:mm"));
    ui->nu_spacetime->setText(QString::number(m_settingHelper->m_MaintainSet.spaceTime));
    ui->nu_valve->setText(QString::number(m_settingHelper->m_MaintainSet.mtRunCount));
    ui->lineEdit_count->setText(QString::number(m_settingHelper->m_MaintainSet.mtCurRunCount));
    ui->dateTimeEdit->setTime(QTime::fromString(m_settingHelper->m_MaintainSet.lastMtTime,"hh:mm"));
}

void MaintaintSetView::writeSetting()
{

    m_settingHelper->m_MaintainSet.sleepTime = ui->nu_autodormantwaittime->text().toInt();
    m_settingHelper->m_MaintainSet.preMtTime = ui->maintaintimeEdit->text();
    m_settingHelper->m_MaintainSet.spaceTime = ui->nu_spacetime->text().toInt();
    m_settingHelper->m_MaintainSet.mtRunCount = ui->nu_valve->text().toInt();
    m_settingHelper->m_MaintainSet.mtCurRunCount = ui->lineEdit_count->text().toInt();
    m_settingHelper->m_MaintainSet.lastMtTime = ui->dateTimeEdit->text();

    m_settingHelper->maintainWriteSetting();
}

void MaintaintSetView::closeEvent(QCloseEvent *e)
{
    Q_UNUSED(e);
    writeSetting();
}
